package com.gitee.wsl.collections.set


import kotlin.js.JsName

/**
 * A HashMap that remembers the order that the elements were added.
 * You can alter the ith element with set(i,value) too :)  Unique list.
 * I need the replace/set-element-i functionality, so I'm subclassing
 * LinkedHashSet.
 */
//open class OrderedHashSet<T> private constructor(
//    private val delegate: LinkedHashSet<T>,
//) : MutableSet<T> by delegate {
//     constructor() : this(LinkedHashSet())
//
//    /**
//     * Track the elements as they are added to the set.
//     */
//    @JsName("myElements")
//    protected var elements: ArrayList<T> = ArrayList()
//
//     fun get(i: Int): T =
//        elements[i]
//
//    /**
//     * Replace an existing value with a new value; updates the element
//     * list and the hash table, but not the key as that has not changed.
//     */
//     fun set(i: Int, value: T): T {
//        val oldElement = elements[i]
//        elements[i] = value         // Update list
//        delegate.remove(oldElement)   // Now update the set: remove/add
//        delegate.add(value)
//        return oldElement
//    }
//
//    fun remove(i: Int): Boolean {
//        val o = elements.removeAt(i)
//        return delegate.remove(o)
//    }
//
//    /**
//     * Add a value to list. Keep in hashtable for consistency also.
//     * Key is object itself. Good for say asking if a certain string is in a list of strings.
//     */
//     override fun add(element: T): Boolean {
//        val result = delegate.add(element)
//
//        if (result) {
//            // Only track if new element not in set
//            elements.add(element)
//        }
//
//        return result
//    }
//
//     override fun remove(element: T): Boolean =
//        throw UnsupportedOperationException()
//
//     override fun clear() {
//        elements.clear()
//        delegate.clear()
//    }
//
//     override fun hashCode(): Int =
//        elements.hashCode()
//
//     override fun equals(other: Any?): Boolean =
//        other is OrderedHashSet<*> && elements == other.elements
//
//     override fun iterator(): MutableIterator<T> =
//        elements.iterator()
//
//    /**
//     * Return the List holding list of table elements.
//     * Note that you are NOT getting a copy so don't write to the list.
//     */
//     fun elements(): List<T> =
//        elements
//
//     override fun toString(): String =
//        elements.toString()
//}
